package org.baseflexcharts.shapes
{
	import flash.display.Shape;
	
	import mx.collections.ArrayCollection;
	import mx.containers.Canvas;
	import mx.controls.Label;
	
	public class Legend extends Canvas
	{
		private var _dataProvider:ArrayCollection = new ArrayCollection();
		
		private var _direction:String;
		
		private var _xOffset:Number = 30;
		
		private var _type:String = "rect"
		
		public static var TYPE_RECT:String = "rect";
		
		public static var TYPE_LINE:String = "line";
		
		public static var VERTICAL:String = "vertical";
		
		public static var HORIZONTAL:String = "horizontal";
		
		public function Legend()
		{
			super();
		}
        
        public function draw():void
        {
        	if (dataProvider == null)
        	{
        		return;
        	}
        	
        	var xValue:uint = 0;
        	var yValue:uint = 0;
        	
        	this.removeAllChildren();
        	
        	for (var i:uint = 0; i < dataProvider.length; i++)
        	{
        		var object:Object = dataProvider.getItemAt(i);
        		        		
        		var label:Label = new Label();
        		label.text = object.name;
        		label.x = xValue + 15;
        		label.y = yValue;
        		this.addChild(label);
        		
        		if (type == "rect")
        		{
	        		var rect:Rectangle = new Rectangle(10, 10, object.color);
	        		rect.x = xValue;
	        		rect.y = yValue; 		
	        		this.addChild(rect);
        		}
        		else if (type == "line")
        		{
        			var shape:Shape = new Shape();
	        		shape.graphics.lineStyle(2, object.color, 1);
	        		shape.graphics.moveTo(xValue, yValue + 10);
	        		shape.graphics.lineTo(xValue + 15, yValue + 10);
	        		this.rawChildren.addChild(shape);
        		}      		
        		
        		if (this.direction == "vertical")
        		{
        		    yValue = yValue + 20;
        		}
        		else
        		{
        			xValue = xValue + xOffset
        		}
        	} 
        }
        
        public function get dataProvider():ArrayCollection
		{
			return this._dataProvider;
		}
        
        public function set dataProvider(data:ArrayCollection):void
        {
        	this._dataProvider = data;
        } 
        
        public function get direction():String
		{
			return this._direction;
		}
        
        public function set direction(data:String):void
        {
        	this._direction = data;
        }
        
        public function get type():String
		{
			return this._type;
		}
        
        public function set type(data:String):void
        {
        	this._type = data;
        }  
        
        public function get xOffset():Number
		{
			return this._xOffset;
		}
        
        public function set xOffset(data:Number):void
        {
        	this._xOffset = data;
        } 
	}
}